import getApiData, { getNestApiData } from '@/services/cpasRequest';
// 获取账套
export async function getAccountInfo(params: { dbname: string }) {
  if (!params.dbname) return [];
  const res = await getApiData('account.accountInfo.getDataList', params);
  if (res.ok) {
    return Promise.resolve({
      data: res.data,
      success: true,
    });
  }
  return Promise.resolve({
    data: [],
    success: false,
  });
}

// 获取左侧树数据
export async function getSubjectCategory(params: { dbname: string }) {
  const res = await getNestApiData('/inventoryAge/category', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}
// 获取右侧表格数据
export async function getSubjectInvList(params: {
  dbname: string;
  Data_ID: string;
  statisticType?: string;
  startYear?: string | number;
  endYear?: string | number;
}) {
  const res = await getNestApiData('/inventoryAge/list', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

// 重新计算库龄
export async function calcInvAge(params: {
  dbname: string;
  Data_ID: string;
  statisticType?: string;
  startYear?: string | number;
  endYear?: string | number;
}) {
  const res = await getNestApiData('/inventoryAge/calc', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

export async function calcInvAgeStatus(params: {
  dbname: string;
  Data_ID: string;
  statisticType?: string;
  startYear?: string | number;
  endYear?: string | number;
}) {
  const res = await getNestApiData('/inventoryAge/calcStatus', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

export async function calcInvAgeCheck(params: {
  dbname: string;
  Data_ID: string;
  statisticType?: string;
  startYear?: string | number;
  endYear?: string | number;
}) {
  const res = await getNestApiData('/inventoryAge/check', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}

export async function stopInvAge(params: {
  dbname: string;
  Data_ID: string;
  statisticType?: string;
}) {
  const res = await getNestApiData('/inventoryAge/stopCalc', 'post', params);
  return Promise.resolve({
    data: res.data,
    success: res.ok,
  });
}
